package com.warm.mini.wework.controller.invoke;

import com.warm.mini.wework.service.invoke.WeworkAuthServiceImpl;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description 企微授权
 * @Author warmchuang
 * @Date 2022/2/11 11:37
 */
@RestController
@RequestMapping("/open/v1/auth/")
public class WeworkAuthController {

    @Resource
    private WeworkAuthServiceImpl authService;

    /**
     * 企业微信自建应用自动授权
     * @param targetUrl
     * @param agentId 应用
     * @param resource
     */
    @RequestMapping("autoAuth")
    public void autoAuth(@RequestParam("resource") String resource,
                         @RequestParam("agentId") String agentId,
                         @RequestParam("targetUrl") String targetUrl){
        authService.autoAuth(resource, agentId, targetUrl);
    }

    @RequestMapping("authBack")
    public void authBack(@RequestParam("resource") String resource,
                         @RequestParam("agentId") String agentId,
                         @RequestParam("targetUrl") String targetUrl,
                         @RequestParam("code") String code){
        authService.authBack(resource, agentId, targetUrl, code);
    }
}
